#!/bin/bash
# date: 2025/5/29
# desc: install ingress-nginx

# ingress-ngnix 控制器解析 ingress

# 场景: 临时测试
# k8s 的 service LoadBalancer 中 externalIPs 指定为 nodeIP , 流量转发流程
# domain -> nodeIP -> kube-proxy拦截进行DNAT转发(tcp) -> ingress-controller-pod(IP:PORT) -> pod(IP:PORT)

install() {
    helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
    helm repo update

    helm install ingress-nginx-ops ingress-nginx/ingress-nginx \
        --namespace ingress-nginx-ops \
        --create-namespace \
        --set controller.ingressClassResource.name=nginx-ops \
        --set controller.ingressClassResource.controllerValue="k8s.io/ingress-nginx-ops" \
        --set controller.service.type=LoadBalancer

    # helm show values ingress-nginx/ingress-nginx
}

uninstall() {
    helm uninstall ingress-nginx-ops
}

case "$0" in
install)
    install
    ;;
uninstall)
    uninstall
    ;;
*)
    echo "$0 install|uninstall"
    ;;
esac
